var kafka = require('kafka-node');
var HighLevelProducer = kafka.HighLevelProducer;
var Client = kafka.Client;
var client = new Client();
//var argv = require('optimist').argv;
var topic = 'topic1';
var count = 1, rets = 0;
var producer = new HighLevelProducer(client);

var hosts = new Array();

hosts.push({
    "type": "snmp",
    "ip": "172.16.0.3",
    "port": "20",
    "host_id": "",
    "user_name": "admin",
    "supername": "admin",
    "superpwd": "sqlwqsc2007",
    "password": "sqlwqsc2007",
    "publiccommunity": "nxepc-pulic",
    "privatecommunity": "nxepc-pulic"
});

hosts.push({
    "type":"host",
    "ip":"172.16.200.111",
    "port": "20",
    "host_id":"",
    "user_name":"xtgs",
    "password":"q1w2e3r4"
});

hostsstr = JSON.stringify(hosts);
console.log(hostsstr);
console.log(hosts);

producer.on('ready', function () {
    setInterval(send, 1000);
});

producer.on('error', function (err) {
    console.log('error', err)
});

function send() {
    //var message = new Date().toString();
    producer.send([
        {topic: topic, messages: hostsstr }
    ], function (err, data) {
        if (err) console.log(err);
        else console.log(hostsstr);
        ++rets;
        if (rets === count) process.exit();
    });
}